﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;
using System.Globalization;
using System.Data;

public partial class MasterPage : System.Web.UI.MasterPage
{
    public string menu;
    int tab = 1;
    public string footer = "";
    public int loaisanphamid = 0;
    private string titleName = "Công Ty TNHH Công Nghệ Thông Tin ITON";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            if (Session["title"] != null)
                title.Text = Session["title"].ToString();
            else
                title.Text = titleName;

            LoadLoaiSanPham();
            LoadBannerQuangCao();
            LoadFooter();
            if (loaisanphamid!=0)
            {
                banner.Visible = false;
            }
            if (Request.QueryString["tab"] != null) tab = Convert.ToInt32(Request.QueryString["tab"]);
            // if (Request.Url.PathAndQuery.ToLower().IndexOf("lienhe.aspx") > 0) tab = 7;
            menu = " <script type='text/javascript' language='javascript'>var ChannelIDSelect=new Array(); ChannelIDSelect[0]='" + tab + "'</script>";
        }
    }

    private void LoadFooter()
    {
        GioiThieuDataSet gioithieuds = new GioiThieuDataSet();
        GioiThieuHelper gioithieuhelper = new GioiThieuHelper();
        gioithieuds = gioithieuhelper.LoadGioiThieuViTri("Footer");
        footer = gioithieuds.GioiThieu[0].NoiDung;
    }

    private void LoadLoaiSanPham()
    {
        LoaiSanPhamDataSet lspds;
        //if (loaisanphamid==0)
        //{
            lspds = new LoaiSanPhamHelper().LoadLoaiSanPhamGoc();
        //}
        //else
        //{
        //    lspds = new LoaiSanPhamHelper().LoadLoaiSanPhamConMenu(loaisanphamid);
        //}
        repMenu.DataSource = lspds.LoaiSanPham;
        repMenu.DataBind();
    }

    protected void repMenu_OnItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            LoaiSanPhamHelper lspHP = new LoaiSanPhamHelper();
            Repeater repCon = ((Repeater)e.Item.FindControl("repMenuCon"));
            repCon.DataSource = (lspHP.LoadLoaiSanPhamCon(Convert.ToInt32((((DataRowView)e.Item.DataItem)["LoaiSanPhamID"]))));
            repCon.DataBind();
        }
    }

    protected void repMenuCon1_OnItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            LoaiSanPhamHelper lspHP = new LoaiSanPhamHelper();
            Repeater repCon = ((Repeater)e.Item.FindControl("repMenuCon"));
            repCon.DataSource = (lspHP.LoadLoaiSanPhamCon(Convert.ToInt32((((DataRowView)e.Item.DataItem)["LoaiSanPhamID"]))));
            repCon.DataBind();
        }
    }

    private void LoadBannerQuangCao()
    {
        //BannerQuangCaoDataSet bnDS = new BannerQuangCaoHelper().LoadBannerQuangCao();
        //repBanner.DataSource = bnDS;
        //repBanner.DataBind();
    }

}
